home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / GAP.TST / PLANGAPX.C < prev    next >
C/C++ Source or Header  |  1995-12-20  |  5KB  |  211 lines

  1. /* ============ */
  2. /* plangap.c    */
  3. /* ============ */
  4. #include <defcodes.h>
  5. #include <mconf.h>
  6. #include <miscdefs.h>
  7. #include <gapdefs.h>
  8. #include <gapprobs.c>
  9. #include <maxgapln.c>
  10.  
  11. /* ------------------- */
  12. /* FUNCTION PROTOTYPES */
  13. /* ------------------- */
  14. # undef F
  15. # if defined(__STDC__) || defined(__PROTO__)
  16. #    define  F( P )  P
  17. # else
  18. #    define  F( P )  ()
  19. # endif
  20.  
  21. /* INDENT OFF */
  22. extern    int    GetMaxGapLen F((double, double, int, int, int, double *,
  23.                 int *));
  24.  
  25. # undef F
  26. /* INDENT ON */
  27.  
  28. /* ==================================================== */
  29. /* PlanCupn - Prints Sample Sizes Required for Gap Test    */
  30. /* ==================================================== */
  31. #define    MAX_GAPS    100
  32. void
  33. main()
  34. {
  35.     AbortGracefully();            /* Make ^C Reasonable */
  36.  
  37.     while (main)
  38.     {
  39.     char    *LeftLbl;
  40.     int    k, m;
  41.     int    CellExpect, MaxGapCt, MinGapCt, WhereMax, WhereMin;
  42.     double  SumCellExpect;
  43.     double    HiLimit, LoLimit, GapProbs[MAX_GAPS+1], TotalProb;
  44.  
  45.     for (;;)
  46.     {
  47.         GetDbl("Enter Lower Limit of Gap [>=0,<1]: ",
  48.         &LoLimit);
  49.         if (LoLimit >= 0 && LoLimit < 1)
  50.         {
  51.         break;
  52.         }
  53.         fprintf(stderr, "Incorrect Entry\n");
  54.     }
  55.  
  56.     for (;;)
  57.     {
  58.         char    Prompt[64];
  59.         sprintf(Prompt, "Enter Upper Limit of Gap [> %g,<=1]: ",
  60.         LoLimit);
  61.  
  62.         GetDbl(Prompt, &HiLimit);
  63.  
  64.         if (HiLimit > LoLimit && HiLimit <= 1)
  65.         {
  66.         break;
  67.         }
  68.         fprintf(stderr, "Incorrect Entry\n");
  69.     }
  70.     MinGapCt = -1; MaxGapCt = -1; WhereMin = -1; WhereMax = -1;
  71.  
  72.     for (k = 0; k < MAX_GAP_LEN; ++k)
  73.     {
  74.         CalcGapProbs(k+1, LoLimit, HiLimit, GapProbs);
  75.  
  76.         {
  77.         double    MaxPerGap = -1;
  78.         for (m = k; m >= 0; --m)
  79.  
  80.         {
  81.             MaxPerGap =
  82.             __max(MaxPerGap, MIN_CELL_XPCT/GapProbs[m]);
  83.         }
  84.         if (MaxPerGap > (double)MAX_NUM_GAPS)
  85.         {
  86.             break;
  87.         }
  88.         else
  89.         {
  90.             MinGapCt = __max((int)MaxPerGap, MinGapCt);
  91.             if (MinGapCt == (int)MaxPerGap)
  92.             {
  93.             WhereMin = k;
  94.             }
  95.         }
  96.         MaxPerGap = -1;
  97.         for (m = k; m >= 0; --m)
  98.         {
  99.             MaxPerGap =
  100.             __max(MaxPerGap, MAX_CELL_XPCT/GapProbs[m]);
  101.         }
  102.         if (MaxPerGap > (double)MAX_NUM_GAPS)
  103.         {
  104.             break;
  105.         }
  106.         if (MaxPerGap > (double)MAX_NUM_GAPS)
  107.         {
  108.             break;
  109.         }
  110.         else
  111.         {
  112.             MaxGapCt = __max((int)MaxPerGap, MaxGapCt);
  113.             if (MaxGapCt == (int)MaxPerGap)
  114.             {
  115.             WhereMax = k;
  116.             }
  117.         }
  118.         }
  119.     }
  120.  
  121.     WhereMax = GetMaxGapLen(LoLimit, HiLimit, MAX_CELL_XPCT,
  122.                 MAX_NUM_GAPS, MAX_GAP_LEN, GapProbs,
  123.                 &MaxGapCt);
  124.     WhereMin = GetMaxGapLen(LoLimit, HiLimit, MIN_CELL_XPCT,
  125.                 MAX_NUM_GAPS, MAX_GAP_LEN, GapProbs,
  126.                 &MinGapCt);
  127.  
  128.     printf("Gap Boundaries: (%g, %g)\n", LoLimit, HiLimit);
  129.     printf("K = %d, MAX_GAP_LEN = %d\n", k, MAX_GAP_LEN);
  130.     printf("MinGapCt = %d (@ k=%d), MaxGapCt = %d (@ k=%d)\n",
  131.         MinGapCt, WhereMin-1, MaxGapCt, WhereMax-1);
  132.     SumCellExpect = TotalProb = 0;
  133. # if 0
  134.     CalcGapProbs(WhereMax+1, LoLimit, HiLimit, GapProbs);
  135. # endif
  136.     CalcGapProbs(WhereMax, LoLimit, HiLimit, GapProbs);
  137.     printf("\nProbabilities for Maximum Cell Expectation (%d)\n",
  138.         MAX_CELL_XPCT);
  139.     printf("Gap Len    Probability           Cell Expectation\n");
  140.  
  141.     for (m = 0; m < WhereMax; ++m)
  142.     {
  143.         double  CellExpect = MaxGapCt * GapProbs[m];
  144.         printf("%4d%23.11e%14.f\n",
  145.         m, GapProbs[m], CellExpect);
  146.         TotalProb += GapProbs[m];
  147.         SumCellExpect += CellExpect;
  148.     }
  149.     printf("Totals:%20.11e%14.f\n", TotalProb, SumCellExpect);
  150.  
  151.     SumCellExpect = TotalProb = 0;
  152. # if 0
  153.     CalcGapProbs(WhereMin+1, LoLimit, HiLimit, GapProbs);
  154. # endif
  155.     CalcGapProbs(WhereMin, LoLimit, HiLimit, GapProbs);
  156.     printf("\nProbabilities for Minimum Cell Expectation (%d)\n",
  157.         MIN_CELL_XPCT);
  158.     printf("Gap Len    Probability           Cell Expectation\n");
  159.     for (m = 0; m < WhereMin; ++m)
  160.     {
  161.         double  CellExpect = MinGapCt * GapProbs[m];
  162.         printf("%4d%23.11e%14.f\n",
  163.         m, GapProbs[m], CellExpect);
  164.         TotalProb += GapProbs[m];
  165.         SumCellExpect += CellExpect;
  166.     }
  167.     printf("Totals:%20.11e%14.f\n", TotalProb, SumCellExpect);
  168. exit(1);
  169.     for (;;)
  170.     {
  171.         GetInt("Enter Maximum Gap Length [> 0]: ",
  172.         &MaxGapCt);
  173.         if (MaxGapCt > 0)
  174.         {
  175.         break;
  176.         }
  177.         fprintf(stderr, "Incorrect Entry\n");
  178.     }
  179.  
  180.     CalcGapProbs(MaxGapCt+1, LoLimit, HiLimit, GapProbs);
  181.  
  182.     for (;;)
  183.     {
  184.               GetInt("Enter Minimum Expectation For Each Gap:\t",
  185.         &CellExpect);
  186.  
  187.         if (CellExpect >= 1)
  188.         {
  189.         break;
  190.         }
  191.         fprintf(stderr, "Incorrect Entry\n");
  192.     }
  193.  
  194.     TotalProb = 0;
  195.     LeftLbl = ">= ";
  196.  
  197.     printf("Gap Len  Gap Probability     Cell Expectation"
  198.            "   # Variates Required\n");
  199.     for (k = MaxGapCt; k >= 0; --k)
  200.     {
  201.         double  DevReqd = ceil(0.5 + CellExpect/GapProbs[k]);
  202.         printf("%3s%3d  %.11e%10s", LeftLbl, k, GapProbs[k], "");
  203.         printf("%5d%15s%5.f\n", CellExpect, "", DevReqd);
  204.         TotalProb += GapProbs[k];
  205.         LeftLbl = "";
  206.     }
  207.  
  208.     printf("%26.11e  (Total)\n", TotalProb);
  209.     }
  210. }
  211.